package com.dongdongshop.controller;

import com.dongdongshop.data.PageBean;
import com.dongdongshop.data.Result;
import com.dongdongshop.data.ResultEnum;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.BrandService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("brand")
public class BrandController {

    @DubboReference
    private BrandService brandService;

    @RequestMapping("brandList")
    public String brandList() {
        return "admin/brand";
    }

    @RequestMapping("findList")
    @ResponseBody
    public Result findList(@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "5")Integer pageSize) {
        PageBean<TbBrand> list = brandService.findList(pageNum,pageSize);
        return Result.ok().setData(list);
    }

    @RequestMapping("selectById")
    @ResponseBody
    public Result selectById(Long id) {
        TbBrand tbBrand = brandService.selectById(id);
        return Result.ok().setData(tbBrand);
    }

    @RequestMapping("updateBrand")
    @ResponseBody
    public Result updateBrand(TbBrand tbBrand) {
        brandService.updateBrand(tbBrand);
        return Result.respones(ResultEnum.SUCCESS);
    }

    @RequestMapping("addBrand")
    @ResponseBody
    public Result addBrand(TbBrand tbBrand) {
        brandService.addBrand(tbBrand);
        return Result.respones(ResultEnum.SUCCESS);
    }

    @RequestMapping("deleteBrand")
    @ResponseBody
    public Result deleteBrand(Long[] id) {
        brandService.deleteBrand(id);
        return Result.respones(ResultEnum.SUCCESS);
    }
}
